﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Snake
{
    class Snake
    {
        private String Direction { get; set; }

        public List<SnakeItem> SnakeBody = new List<SnakeItem>();     
               
                
        public Snake(int x, int y)
        : this()
        {
            SnakeItem head = new SnakeItem(x, y);
            SnakeItem neck = new SnakeItem(x + 1, y);
            SnakeItem tale = new SnakeItem(x + 2, y);
            SnakeBody.Add(head);
            SnakeBody.Add(neck);
            SnakeBody.Add(tale);
        }

        public Snake()
        {
            this.SnakeBody = new List<SnakeItem>();
            this.Direction = "left";
        }
        
        public class SnakeItem
        {
         public int X { get; set; }
         public int Y { get; set; }

         
         public int GetStartXCoordinate()
         {
             Field field = new Field();
             int x = field.Width / 2;
             return x;
         }

         public int GetStartYCoordinate()
         {
             Field field = new Field();
             int y = field.Height / 2;
             return y;
         }


         public SnakeItem(int x, int y)
             : this()
         {
             this.X = x;
             this.Y = y;
         }

        public SnakeItem()
        {
             this.X = 1;
             this.Y = 1;
        }

            
    }

        //public void Move(Snake s)
        //{
        //    string direction = "left";
        //    if (direction == "left")
        //    {               

        //        for (int i = 0; i < SnakeBody.Count; i++)
        //        {
        //            Snake.SnakeItem item = SnakeBody[i];
        //            item.X = item.X - 1;
        //            item.Y = item.Y;
                    
        //        }
        //    }
        //}

        public void Move(string direction)
        {
            if (direction == "LeftArrow")
            {
                foreach (SnakeItem i in SnakeBody)
                {
                    i.X -= 1;                  
                }
            }
            else if (direction == "RightArrow")
            {
                foreach (SnakeItem i in SnakeBody)
                {
                    i.X += 1;
                }
            }
            else if (direction == "UpArrow")
            {
                foreach (SnakeItem i in SnakeBody)
                {
                    i.Y -= 1;                  
                }
            }
            else if (direction == "DownArrow")
            {
                foreach (SnakeItem i in SnakeBody)
                {
                    i.Y += 1;
                }
            }
        }

        public string ChangeSnakeDirection(string newDirection)
        {
            this.Direction = newDirection;
            return this.Direction; 
        }
    }

}
